package com.contextor.magiccards.model.errors;

/**
 * User: Sergey
 * Date: 14.03.2011 22:56:33
 */
public class MagicCardsException extends Exception {
    protected ErrorCode code;

    public MagicCardsException(String message) {
        super(message);
    }

    public MagicCardsException(Throwable cause) {
        super(cause);
    }

    public MagicCardsException(String message, ErrorCode errorCode) {
        super(message);
    }

    public ErrorCode getCode() {
        return (code == null ? ErrorCode.UNKNOWN_ERROR : code);
    }

    public void setCode(ErrorCode code) {
        this.code = code;
    }


    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append(super.toString());
        builder.append("[");

        if (this.getCode() != null) {
            builder.append("error=").append(this.getCode().name());
        }

        if (this.getMessage() != null && this.getMessage().length() > 0) {
            builder.append(" msg=").append(this.getMessage());
        }
        return builder.append(" ]").toString();
    }

}
